/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProjectMilestones.java
 *
 * Created on Jul 4, 2011, 1:55:29 AM
 */

package javadatabasegui;

import java.awt.Component;
import java.awt.Font;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author PM
 */
public class ProjectMilestones extends javax.swing.JFrame {
    int projectID;
    String userEmail;
    Connection con;
    String msName = "Milestone Name";
    /** Creates new form ProjectMilestones */
    public ProjectMilestones(int pID, String uEmail, Connection conn) {
        projectID = pID;
        userEmail = uEmail;
        con = conn;
        initComponents();
        displayMilestoneTable();
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        label1 = new java.awt.Label();
        jButton1 = new javax.swing.JButton();
        label2 = new java.awt.Label();
        label3 = new java.awt.Label();
        label4 = new java.awt.Label();
        label5 = new java.awt.Label();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel4 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Project Milestones - Accounting Report System");
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 20));
        jLabel1.setText("Project Milestones");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setText("Project");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel3.setText("Project Manager");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel4.setText("Description");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel7.setText(getProjectName());
        jLabel7.setPreferredSize(new java.awt.Dimension(75, 15));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel8.setText(getManagerName());
        jLabel8.setPreferredSize(new java.awt.Dimension(75, 15));

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel5.setForeground(new java.awt.Color(0, 0, 255));
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("<html><U>Dashboard</U><html>");
        jLabel5.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                DashboardMouseClicked(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel6.setForeground(new java.awt.Color(0, 0, 255));
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("<html><U>Project Info</U><html>");
        jLabel6.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ProjectInfoMouseClicked(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel9.setText(getDescription());

        jPanel2.setBackground(new java.awt.Color(226, 232, 255));

        label1.setFont(new java.awt.Font("Tahoma", 1, 18));
        label1.setText("Milestones");

        jButton1.setText("New Milestone");
        jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                MSMouseClicked(evt);
            }
        });

        label2.setFont(new java.awt.Font("Tahoma", 1, 14));
        label2.setText("Status");

        label3.setFont(new java.awt.Font("Tahoma", 1, 14));
        label3.setText("Name");

        label4.setFont(new java.awt.Font("Tahoma", 1, 14));
        label4.setText("Total Tasks");

        label5.setFont(new java.awt.Font("Tahoma", 1, 14));
        label5.setText("Active Tasks");

        jSeparator1.setForeground(new java.awt.Color(0, 0, 0));

        jScrollPane1.setBorder(null);

        jPanel4.setBackground(new java.awt.Color(226, 232, 255));
        jPanel4.setPreferredSize(new java.awt.Dimension(585, 261));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 588, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 261, Short.MAX_VALUE)
        );

        jScrollPane1.setViewportView(jPanel4);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 605, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 605, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(41, 41, 41)
                                .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(100, 100, 100)
                        .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 140, Short.MAX_VALUE)
                        .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(31, 31, 31)
                                .addComponent(jButton1))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                            .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(22, 22, 22)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(230, 174, 39));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 625, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 65, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 245, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel9)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(3, 3, 3)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel9)))
                .addGap(33, 33, 33)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(89, 89, 89))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 562, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void DashboardMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DashboardMouseClicked
        new UserDashboard(userEmail, con).setVisible(true);
            this.dispose();
    //Opens the User Dashboard if clicked
    }//GEN-LAST:event_DashboardMouseClicked

    private void ProjectInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ProjectInfoMouseClicked
        new ProjectInfo(projectID,userEmail, con).setVisible(true);
            this.dispose();
    //Opens the Project Info page if clicked
    }//GEN-LAST:event_ProjectInfoMouseClicked

    private void MSMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MSMouseClicked
        new MilestoneInfo(userEmail, projectID, con, msName, true).setVisible(true);
            this.dispose();
    //Opens blank Milestone Info page if clicked
    }//GEN-LAST:event_MSMouseClicked

    private String getProjectName(){
        //Query to get name from ID.
        return "Project" + projectID; //this changes to name
    }

    private String getDescription(){
        String description = "Description";
        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            if (stmt.execute("SELECT P_Desc FROM cs4400_Group_14.Project WHERE Project.PID = \"" + projectID + "\"")){
                rs = stmt.getResultSet();
            }
            rs.next();
            description = rs.getString("P_Desc");
        }catch(SQLException e){
                System.err.println(e.getMessage());
                System.err.println(e.getSQLState());
        }
        return description;
    }

    private String getManagerName(){
        String dashName = "Name";
        //use userEmail to get the F_Name and L_Name
        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            if (stmt.execute("SELECT F_Name,L_Name FROM cs4400_Group_14.Project,"
                    + "cs4400_Group_14.Users WHERE Project.Mgr_Email = Users.Email"
                    + " AND Project.PID = \"" + projectID + "\"")){
                rs = stmt.getResultSet();
            }
            rs.next();
            dashName = rs.getString("F_Name") + " " + rs.getString("L_Name");
        }catch(SQLException e){
            System.err.println(e.getMessage());
            System.err.println(e.getSQLState());
        }        
        return dashName;
    }
    
    private void displayMilestoneTable(){
        int tblEntries = 0;
        
        // Getting the needed size of the box
        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            if (stmt.execute("SELECT COUNT(M_Name) from `cs4400_Group_14`.`Milestones` WHERE `PID` = \"" + projectID + "\"")){
                rs = stmt.getResultSet();
            }
            rs.next();
            tblEntries = rs.getInt("COUNT(M_Name)");
            System.out.println("#milestones= " + tblEntries);
        }catch(SQLException e){
            System.err.println("Error in Milestone Count");
            System.err.println(e.getMessage());
            }
        
        //Sets the size of the panel to the correct height for the number of entries.
        jPanel4.setPreferredSize(new java.awt.Dimension(585, tblEntries*15));
        
        //Creats an array type to hold the labels (labels are each line in the panel)
        javax.swing.JLabel[] tstLabel = new javax.swing.JLabel[tblEntries];
        
        //Fills the array with new labels.
        for(int i=0; i<tstLabel.length; i++){
            tstLabel[i] = new javax.swing.JLabel();
        }
        
        //This try catch block will get the data from the database for each line
        //that we want to show. It will put that data into the labels of the array
        //created above.
        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            Date currentDate = getDate();
            if (stmt.execute("SELECT Milestones.Status, Milestones.M_Name, COUNT(Tasks.T_Name), SUM(Tasks.Status), Milestones.Due_Date FROM `cs4400_Group_14`.`Milestones` LEFT OUTER JOIN `cs4400_Group_14`.`Tasks` ON Tasks.M_Name = Milestones.M_Name AND Milestones.PID = Tasks.PID WHERE Milestones.PID = \"" + projectID + "\" GROUP BY M_Name ORDER BY Milestones.Due_Date ASC")){
                rs = stmt.getResultSet();
            }
            // START formatting of table
            for(int i=0; rs.next();i++){
                if( currentDate.after(rs.getDate("Due_Date")) && rs.getInt("Milestones.Status") == 1) {
                    tstLabel[i].setText("<html> <body> <table width=\"585\"> <tr> <td width=\"30%\"> <span style=\"color:red\">" + "Overdue since " + rs.getDate("Due_Date") + "</td>"
                        + "<td width=\"40%\"> <u><span style=\"color:blue\">" + rs.getString("M_Name") + "</u></td>"
                        + "<td width=\"20%\">" + rs.getInt("SUM(Tasks.Status)") + "</td>"
                        + "<td width=\"10%\">" + rs.getInt("COUNT(Tasks.T_Name)") + "</td> </tr> </table> </body> </html>");
                    tstLabel[i].setName(rs.getString("M_Name"));
                }
                else {
                    if( currentDate.before(rs.getDate("Due_Date")) && rs.getInt("Milestones.Status") == 1) {
                    tstLabel[i].setText("<html> <body> <table width=\"585\"> <tr> <td width=\"30%\">" + "Active until " + rs.getDate("Due_Date") + "</td>"
                        + "<td width=\"40%\"> <u><span style=\"color:blue\">" + rs.getString("M_Name") + "</u></td>"
                        + "<td width=\"20%\">" + rs.getInt("SUM(Tasks.Status)") + "</td>"
                        + "<td width=\"10%\">" + rs.getInt("COUNT(Tasks.T_Name)") + "</td> </tr> </table> </body> </html>");
                    tstLabel[i].setName(rs.getString("M_Name"));
                }
                    else {
                        tstLabel[i].setText("<html> <body> <table width=\"585\"> <tr> <td width=\"30%\">" + "Complete" + "</td>"
                        + "<td width=\"40%\"> <u><span style=\"color:blue\">" + rs.getString("Milestones.M_Name") + "</u></td>"
                        + "<td width=\"20%\">" + rs.getInt("SUM(Tasks.Status)") + "</td>"
                        + "<td width=\"10%\">" + rs.getInt("COUNT(Tasks.T_Name)") + "</td> </tr> </table> </body> </html>");
                        tstLabel[i].setName(rs.getString("M_Name"));
                    }
                }
            }
        }catch(SQLException e){
            System.err.println("Error in displaying milestones");
            System.err.println(e.getMessage());
            }

        //this is much easier to display the components in the panel
        for(int i=0; i<tstLabel.length; i++){
            tstLabel[i].setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
            tstLabel[i].addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                milestoneClicked(evt);
            }});
        }

        jPanel4.setLayout(new GridBagLayout());
        GridBagConstraints cnst = new GridBagConstraints();       
        for(int i=0; i<tstLabel.length; i++){
            tstLabel[i].setFont(new Font(tstLabel[i].getText(),4,12));
            cnst.gridx = 0;
            cnst.gridy = i;
            jPanel4.add(tstLabel[i],cnst);
        }
        cnst.gridy = tstLabel.length;
        cnst.gridx = 0;
        cnst.weighty = tblEntries * 15;
        jPanel4.add(new javax.swing.JLabel(), cnst);
        

    }
    
    private Date getDate(){
        Calendar cal = Calendar.getInstance();
        return cal.getTime();        
    }
    
    private void milestoneClicked(java.awt.event.MouseEvent evt ) {
        Component cmp = evt.getComponent();
        String str = cmp.getName();
        new MilestoneInfo(userEmail, projectID, con, str).setVisible(true);
            this.dispose();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private java.awt.Label label1;
    private java.awt.Label label2;
    private java.awt.Label label3;
    private java.awt.Label label4;
    private java.awt.Label label5;
    // End of variables declaration//GEN-END:variables

}
